﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WebLibs;

namespace MDF.DataHelper.DataObject.UsersDO
{
    public class UserInGroupsDAO : BaseDataObject
    {
        #region Constructor

        public UserInGroupsDAO()
        {
        }

        public UserInGroupsDAO(IData _objData)
        {
            this.m_objData = _objData;
        }
        #endregion

        #region Methods

        public DataTable GetByGroupID(int GroupID)
        {

            DataTable dtResult = new DataTable();
            try
            {
                this.Connect();
                this.m_objData.CreateNewStoredProcedure("[UserInGroups_Select]");
                this.m_objData.AddParameter("@UserGroupID", GroupID);
                dtResult = this.m_objData.ExecStoreToDataTable();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                this.DeConnect();
            }
            return dtResult;
        }

        #endregion

        public DataTable GetByUserID(int _iUserID)
        {
            DataTable dtResult = new DataTable();
            try
            {
                this.Connect();
                this.m_objData.CreateNewStoredProcedure("[UserInGroups_SelectByUserID]");
                this.m_objData.AddParameter("@UserID", _iUserID);
                dtResult = this.m_objData.ExecStoreToDataTable();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                this.DeConnect();
            }
            return dtResult;
        }

        public void Insert(int UserID, int GroupID)
        {

            DataTable dtResult = new DataTable();
            try
            {
                this.Connect();
                this.m_objData.CreateNewStoredProcedure("[UserInGroups_Insert]");
                this.m_objData.AddParameter("@UserID", UserID);
                this.m_objData.AddParameter("@GroupID", GroupID);
                this.m_objData.ExecNonQuery();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                this.DeConnect();
            }
        }
    }
}
